package com.blog.web.controller;

import com.blog.common.core.domain.R;
import com.blog.common.core.web.domain.AjaxResult;
import com.blog.common.core.web.page.TableDataInfo;
import com.blog.common.domain.vo.ArticleHomeVo;
import com.blog.common.domain.vo.CategoryVo;
import com.blog.web.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 分类控制器
 * </p>
 *
 * @author Valerie
 * @date 2023/2/27
 **/
@RestController
@Slf4j
@Api(tags = "分类控制器")
public class CategoryController {

    @Resource
    private CategoryService categoryService;


    /**
     * 查看分类列表
     * @param
     * @return {@link R<TableDataInfo<CategoryVo>>} message
     */
    @ApiOperation(value = "查看分类列表")
    @GetMapping("/categories")
    public R<TableDataInfo<CategoryVo>> listCategories(@RequestParam(value = "pageSize", required = false) Serializable pageSize){
        return R.ok(categoryService.listCategories(pageSize));
    }

    /**
     * 根据分类查询文章
     *
     * @param categoryId 分类id
     * @return {@link R<List<ArticleHomeVo>>}
     */
    @ApiOperation("根据分类查询文章")
    @GetMapping("/articlesByCategory")
    public R<List<ArticleHomeVo>> listArticlesByCategory(@RequestParam("categoryId") Serializable categoryId){
        return R.ok(categoryService.listArticlesByCategory(categoryId));
    }

}
